import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2024-08-22
 * Time: 17:15
 */
public class MyStack {
    public int[] elem;
    public int useSize;

    public  MyStack(){
        this.elem = new int[10];
    }

    public void push(int val){
        if(isFull()){
            this.elem = Arrays.copyOf(elem,2*elem.length);
        }
        elem[useSize++] = val;
    }

    public boolean isFull(){
        return useSize == elem.length;
    }

    public int pop(){
        if(isEmpty()){
            throw new EmptyStackEcpetion("栈为空");
        }
        int cur = elem[useSize-1];
        useSize--;
        return cur;
    }

    //找到栈顶元素，但不删除
    public int peek(){
        if(isEmpty()){
            return -1;
        }
        return  elem[useSize-1];
    }

    public boolean isEmpty(){
        return useSize == 0;
    }
}
